/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cmp.core.utilities;

import com.jme3.math.Vector3f;

/**
 *
 * @author krummer
 */
public class PhysicsUtility {
    public static Vector3f calculateVerticalLaunchSpeed(float gravity, float verticalLaunchSpeed, Vector3f launchPoint, Vector3f target) {
        Vector3f dir = target.subtract(launchPoint);
        float height = dir.y;
        dir.y = 0;
        float distance = dir.length();
        dir.normalizeLocal();
        Vector3f launchSpeed = dir.mult(verticalLaunchSpeed);
        launchSpeed.y = (height - gravity / 2.f 
                * (distance / verticalLaunchSpeed) 
                * (distance / verticalLaunchSpeed))
                * verticalLaunchSpeed / distance;
        return launchSpeed;
    }
}
